package cn.mux.jdk8.date;

import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.MonthDay;
import java.time.Year;
import java.time.YearMonth;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;

public class NewDate {
	public static void main(String[] args) {
		//获取当前clock
		Clock clock = Clock.systemUTC();
		//通过clock 获取当前时刻
		System.out.println("当前时刻："+clock.instant());
		//获取clock 对应的毫秒数
		System.out.println(clock.millis());
		System.out.println(System.currentTimeMillis());
		//duration 用法
		Duration duration = Duration.ofSeconds(6000);
		System.out.println("6000秒相当于："+duration.toMinutes()+"分");
		System.out.println("6000秒相当于："+duration.toHours()+"小时");
		System.out.println("6000秒相当于："+duration.toDays()+"天");
		//在clock 的基础上增加6000秒，并返回新的clock
		
		Clock clock2 = Clock.offset(clock,duration);
		System.out.println(clock2.instant());
		//下面关于instant 用法 
		//获取当前时间
		Instant instant = Instant.now();
		System.out.println(instant);
		//instant 添加6000秒，返回新的instant
		Instant instant2 = instant.plusSeconds(6000);
		System.out.println(instant2);
		
		//根据字符串解析Instant 对象
		Instant instant3 = Instant.parse("2016-08-09T12:42:46.466Z");
		System.out.println(instant3);
		//在instant3 的基础上添加5小时4分钟
		Instant instant4 =instant3.plus(Duration.ofHours(5).plusMinutes(4));
		System.out.println(instant4);
		
		//获取instant4 5天以前的时刻
		Instant instant5 = instant4.minus(Duration.ofDays(5));
		System.out.println(instant5);
		//下面是localDate 的用法
		LocalDate localDate = LocalDate.now();
		System.out.println(localDate);
		//获得2014年的第146天
		localDate = LocalDate.ofYearDay(2014,146);
		System.out.println(localDate);
		
		//设置为2014 年5月21日
		localDate = LocalDate.of(2014,Month.MAY,21);
		System.out.println(localDate);
		
		//下面是关于localtime的用法
		LocalTime localTime = LocalTime.now();
		//设置为22点33分
		localTime = LocalTime.of(22, 33);
		System.out.println(localTime);
		//返回一天中的第5503秒
		localTime = LocalTime.ofSecondOfDay(5503);
		System.out.println(localTime);
		
		//下面是localdatetime 用法
		LocalDateTime localDateTime = LocalDateTime.now();
		//当前时间加上 25小时3分钟
		LocalDateTime future = localDateTime.plusHours(25).plusMinutes(3);
		System.out.println(future);
		//下面关于Year,YearMonth,MonthDay
		Year year  = Year.now();
		System.out.println("当前年份："+year);
		year = year.plusYears(5);//当前年份加5
		System.out.println(year);
		//根据指定月份获取yearmonth
		YearMonth ym =year.atMonth(10);
		System.out.println("year 年10月"+ym);
		
		//当前年月再加5年，减3个月
		ym = ym.plusYears(5).minusMonths(3);
		System.out.println(ym);
		
		MonthDay monthDay = MonthDay.now();
		System.out.println(monthDay);
		//设置为5月23日
		MonthDay monthDay2 = monthDay.with(Month.MAY).withDayOfMonth(23);
		System.out.println(monthDay2);
		
		//patter
		String string = "123535";
		System.out.println(string.replaceFirst("\\d*","a"));
		System.out.println(".......");
		
		Matcher m = Pattern.compile("\\d*").matcher(string);
		
		while(m.find()){
			System.out.println(m.group());
		}
		
		
		
		
		
		
		
		
	}
}